import requests
from bs4 import BeautifulSoup

# 假设要获取网页内容
url = 'https://www.cvf.org.cn/channels/32.html'  # 替换为实际的网页 URL
try:
    response = requests.get(url)
    # 尝试从响应头中获取编码，如果没有则默认使用 UTF-8
    response.encoding = response.apparent_encoding
    response.raise_for_status()  # 检查请求是否成功
    html_content = response.text

    # 创建 BeautifulSoup 对象
    soup = BeautifulSoup(html_content, 'html.parser')

    # 查找 class 为 info_body 的 div 标签
    info_body_div = soup.find('div', class_='info_body')

    if info_body_div:
        # 查找 div 标签内的所有 p 标签
        p_tags = info_body_div.find_all('p')

        # 提取 p 标签的完整 HTML 内容，并去掉换行符
        p_htmls = [str(p).replace('\n', '') for p in p_tags]
        # 打印或处理提取的内容
        strhtml = ''
        for html in p_htmls:
            strhtml+=html
        print(strhtml)
    else:
        print("未找到 class 为 info_body 的 div 标签。")

except requests.RequestException as e:
    print(f"请求网页时出现错误: {e}")
except Exception as e:
    print(f"发生未知错误: {e}")
    